<!DOCTYPE html>
<html lang="cn-zh">

<head>
  

  
  


  <meta charset="utf-8">


  <meta name="robots" content="noindex, nofollow, noarchive">


<meta name="viewport" content="width=device-width, initial-scale=1.0">


  
    
      <meta name="description" content="开发的乐趣在于相通而不同">
    
  


<meta name="color-scheme" content="light dark">







<meta name="generator" content="Hugo 0.111.2">

<meta content="" name="keywords">
<meta content="通通不同-博客" property="og:title">
<meta content="开发的乐趣在于相通而不同" property="og:description">

<meta name="msvalidate.01" content="F56ED94B7E86941E3DACEF208F07D329" />

  <title>
    
    通通不同-博客
    
</title>

  <link rel="canonical" href="https://codebeautiful.gitee.io/">


  <link rel="alternate" type="application/rss+xml" href="/index.xml" title="通通不同-博客">

  








  

  
    
    
    
      
      
    
    
    
  
    
    
    
      
      
    
    
    
  
    
    
    
      
      
    
    
    
  
    
    
    
      
      
    
    
    
  


  
  <link rel="stylesheet" href="/css/base.min.4f231885947d13c748c815d93da49f07ab89afb67629f9970b7c054610e88e0b.css" integrity="sha256-TyMYhZR9E8dIyBXZPaSfB6uJr7Z2KfmXC3wFRhDojgs=" crossorigin="anonymous">



</head>

<body>
  <nav class="u-background">
  <div class="u-wrapper">
    <ul class="Banner">
      <li class="Banner-item Banner-item--title">
        <h1 class="Banner-heading">
          <a class="Banner-link u-clickable" href="/">通通不同-博客</a>
        </h1>
      </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/post/">全部</a>
        </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/categories/">分类</a>
        </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/tags/">标签</a>
        </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/about/">关于</a>
        </li>
      
    </ul>
  </div>
</nav>

  <main>
    <div class="u-wrapper">
      <div class="u-padding">
        

  
    <article>
      <header class="Heading">
  <h2 class="Heading-title">
    <a class="Heading-link u-clickable" href="/post/linux_create_user/" rel="bookmark">linux创建新用户</a>
  </h2>
  
    <time datetime="2023-03-21T15:23:06&#43;08:00">21 March, 2023</time>
  
</header>

      
        <h3 id="创建用户">
  <a class="Heading-link u-clickable" href="/post/linux_create_user/#%e5%88%9b%e5%bb%ba%e7%94%a8%e6%88%b7">创建用户</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>useradd -d /home/test -m test</span></span></code></pre></div>
<blockquote>
<p>useradd：创建新用户</p>
</blockquote>
<ul>
<li>-d 指定目录文件夹</li>
<li>-m 新账号名</li>
<li>-c comment 指定一段注释性描述</li>
<li>-d 目录 指定用户主目录，如果此目录不存在，则同时使用-m选项，可以创建主目录</li>
<li>-g 用户组 指定用户所属的用户组</li>
<li>-G 用户组，用户组 指定用户所属的附加组</li>
<li>-s Shell文件 指定用户的登录Shell</li>
<li>-u 用户号 指定用户的用户号，如果同时有-o选项，则可以重复使用其他用户的标识号</li>
</ul>
<h3 id="设置密码">
  <a class="Heading-link u-clickable" href="/post/linux_create_user/#%e8%ae%be%e7%bd%ae%e5%af%86%e7%a0%81">设置密码</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>passwd test</span></span></code></pre></div>
<p>会提示你输入两次密码</p>
<h3 id="删除账号">
  <a class="Heading-link u-clickable" href="/post/linux_create_user/#%e5%88%a0%e9%99%a4%e8%b4%a6%e5%8f%b7">删除账号</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>userdel test</span></span></code></pre></div>

      
      


  

  

  





  <footer>
    
      
    
      
    
      
        <ul class="Tags">
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/linux/" rel="tag">linux</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/%E5%88%9B%E5%BB%BA%E7%94%A8%E6%88%B7/" rel="tag">创建用户</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/%E8%AE%BE%E7%BD%AE%E5%AF%86%E7%A0%81/" rel="tag">设置密码</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/%E5%88%A0%E9%99%A4%E8%B4%A6%E5%8F%B7/" rel="tag">删除账号</a>
            </li>
          
        </ul>
      
    
  </footer>

    </article>
    
      <div class="Divider"></div>
    
  
    <article>
      <header class="Heading">
  <h2 class="Heading-title">
    <a class="Heading-link u-clickable" href="/post/system_monitor/" rel="bookmark">服务器运维监控命令汇总</a>
  </h2>
  
    <time datetime="2023-03-21T14:25:13&#43;08:00">21 March, 2023</time>
  
</header>

      
        <h1 id="who命令">
  <a class="Heading-link u-clickable" href="/post/system_monitor/#who%e5%91%bd%e4%bb%a4">who命令</a>
</h1>
<p>输出信息包括 用户名，终端类型，登录日期，访问IP
-H 打印列标题
-b 查看上次启动时间</p>

<pre tabindex="0"><code>who [-H|-b]
who [-H|-b] /var/log/wtmp</code></pre>
<h1 id="查看命令历史">
  <a class="Heading-link u-clickable" href="/post/system_monitor/#%e6%9f%a5%e7%9c%8b%e5%91%bd%e4%bb%a4%e5%8e%86%e5%8f%b2">查看命令历史</a>
</h1>
<ul>
<li>每个用户都有一份命令历史记录</li>
<li>查看$HOME/.bash_history</li>
<li>或者在终端输入： history</li>
</ul>
<h1 id="last命令">
  <a class="Heading-link u-clickable" href="/post/system_monitor/#last%e5%91%bd%e4%bb%a4">last命令</a>
</h1>
<ul>
<li>查看用户登录历史</li>
<li>命令会读取 /var/log/wtmp文件；</li>
<li>/var/log/btmp可以显示远程登陆信息。</li>
<li>last默认打印所有用户的登陆信息。</li>
<li>如果想打印某个用户的登陆信息，可以使用</li>
<li>last 用户名</li>
</ul>
<p>选项：</p>
<ul>
<li>（1）-x：显示系统开关机以及执行等级信息</li>
<li>（2）-a：将登陆ip显示在最后一行</li>
<li>（3）-f ：读取特定文件，可以选择 -f /var/log/btmp文件</li>
<li>（4）-d：将IP地址转换为主机名</li>
<li>（5）-n：设置列出名单的显示列数</li>
<li>（6）-t：查看指定时间的用户登录历史</li>
</ul>
<h1 id="lastlog命令">
  <a class="Heading-link u-clickable" href="/post/system_monitor/#lastlog%e5%91%bd%e4%bb%a4">lastlog命令</a>
</h1>
<blockquote>
<p>查看所有用户最近一次登录历史</p>
</blockquote>
<blockquote>
<p>命令将读取/var/log/lastlog文件；用户排列顺序按照/etc/passwd中的顺序</p>
</blockquote>
<p>选项：</p>
<ul>
<li>（1） -u：查看某个用户的最后一次登陆历史</li>
<li>（2） -t：查看最近几天之内的用户登录历史</li>
<li>（3） -b：查看指定天数之前的用户登录历史</li>
</ul>
<h1 id="ac命令">
  <a class="Heading-link u-clickable" href="/post/system_monitor/#ac%e5%91%bd%e4%bb%a4">ac命令</a>
</h1>
<blockquote>
<p>根据/var/log/wtmp文件中的登陆和退出时间报告用户连接的时间（小时），默认输出报告总时间</p>
</blockquote>
<ul>
<li>（1）-p：显示每个用户的连接时间</li>
<li>（2）-d：显示每天的连接时间</li>
<li>（3）-y：显示年份，和-d配合使用</li>
</ul>

      
      


  

  

  





    </article>
    
      <div class="Divider"></div>
    
  
    <article>
      <header class="Heading">
  <h2 class="Heading-title">
    <a class="Heading-link u-clickable" href="/post/supervisor/" rel="bookmark">Supervisor管理GO程序</a>
  </h2>
  
    <time datetime="2023-03-21T14:04:34&#43;08:00">21 March, 2023</time>
  
</header>

      
        <h3 id="安装">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e5%ae%89%e8%a3%85">安装</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>apt-get install supervisor</span></span></code></pre></div>
<h3 id="使用说明">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e4%bd%bf%e7%94%a8%e8%af%b4%e6%98%8e">使用说明</a>
</h3>
<p>supervisor配置文件：/etc/supervisor/supervisord.conf
子进程配置文件路径：/etc/supervisor/conf.d/</p>
<h3 id="常用命令说明">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e8%af%b4%e6%98%8e">常用命令说明</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 查看所有进程的状态</span>
</span></span><span style="display:flex;"><span>supervisorctl status
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 停止iot</span>
</span></span><span style="display:flex;"><span>supervisorctl stop iot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 启动iot</span>
</span></span><span style="display:flex;"><span>supervisorctl start iot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 重启iot</span>
</span></span><span style="display:flex;"><span>supervisorctl restart iot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 配置文件修改后使用该命令加载新的配置</span>
</span></span><span style="display:flex;"><span>supervisorctl update
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 重新启动配置中的所有程序</span>
</span></span><span style="display:flex;"><span>supervisorctl reload</span></span></code></pre></div>
<h3 id="配置go进程">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e9%85%8d%e7%bd%aego%e8%bf%9b%e7%a8%8b">配置GO进程</a>
</h3>

<pre tabindex="0"><code class="language-conf" data-lang="conf">[program:iot]
# 脚本目录
directory=/opt/iot
# 脚本执行命令
command=/opt/iot/main
# 日志输出
stdout_logfile=/opt/iot/supervisor/main.log
# supervisor启动的时候是否随着同时启动，默认True
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true</code></pre>
<h3 id="常见问题">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98">常见问题</a>
</h3>
<ol>
<li>unix:///var/run/supervisor.sock no such file</li>
</ol>
<blockquote>
<p>问题描述：安装好supervisor没有开启服务直接使用supervisorctl报的错</p>
</blockquote>
<blockquote>
<p>解决办法：supervisord -c /etc/supervisord.conf</p>
</blockquote>
<ol start="2">
<li>command中指定的进程已经起来，但supervisor还不断重启</li>
</ol>
<blockquote>
<p>问题描述：command中启动方式为后台启动，导致识别不到pid，然后不断重启，这里使用的是elasticsearch，command指定的是$path/bin/elasticsearch -d</p>
</blockquote>
<blockquote>
<p>解决办法：supervisor无法检测后台启动进程的pid，而supervisor本身就是后台启动守护进程，因此不用担心这个</p>
</blockquote>
<ol start="3">
<li>启动了多个supervisord服务，导致无法正常关闭服务</li>
</ol>
<blockquote>
<p>问题描述：在运行supervisord -c /etc/supervisord.conf之前，直接运行过supervisord -c /etc/supervisord.d/xx.conf导致有些进程被多个superviord管理，无法正常关闭进程。</p>
</blockquote>
<blockquote>
<p>解决办法：使用ps -fe | grep supervisord查看所有启动过的supervisord服务，kill相关的进程。</p>
</blockquote>

      
      


  

  

  





  <footer>
    
      
    
      
    
      
        <ul class="Tags">
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/supervisor/" rel="tag">Supervisor</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/go%E7%9A%84%E5%AE%88%E6%8A%A4%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86/" rel="tag">GO的守护进程管理</a>
            </li>
          
        </ul>
      
    
  </footer>

    </article>
    
      <div class="Divider"></div>
    
  
    <article>
      <header class="Heading">
  <h2 class="Heading-title">
    <a class="Heading-link u-clickable" href="/post/config/" rel="bookmark">使用hugo配置博客文档</a>
  </h2>
  
    <time datetime="2023-03-11T23:16:37&#43;08:00">11 March, 2023</time>
  
</header>

      
        <h3 id="安装">
  <a class="Heading-link u-clickable" href="/post/config/#%e5%ae%89%e8%a3%85">安装</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ brew install hugo</span></span></code></pre></div>
<h3 id="生成博客">
  <a class="Heading-link u-clickable" href="/post/config/#%e7%94%9f%e6%88%90%e5%8d%9a%e5%ae%a2">生成博客</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ hugo new site myblog</span></span></code></pre></div>
<h3 id="安装皮肤">
  <a class="Heading-link u-clickable" href="/post/config/#%e5%ae%89%e8%a3%85%e7%9a%ae%e8%82%a4">安装皮肤</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ cd themes
</span></span><span style="display:flex;"><span>$ git clone https://github.com/de-souza/hugo-flex.git</span></span></code></pre></div>
<h3 id="创建文章">
  <a class="Heading-link u-clickable" href="/post/config/#%e5%88%9b%e5%bb%ba%e6%96%87%e7%ab%a0">创建文章</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>$ hugo new post/config.md</span></span></code></pre></div>
<h3 id="运行hugo">
  <a class="Heading-link u-clickable" href="/post/config/#%e8%bf%90%e8%a1%8chugo">运行hugo</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>hugo server -D --theme<span style="color:#f92672">=</span>hugo-flex --buildDrafts</span></span></code></pre></div>
<h3 id="部署">
  <a class="Heading-link u-clickable" href="/post/config/#%e9%83%a8%e7%bd%b2">部署</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>hugo --theme<span style="color:#f92672">=</span>hugo-flex --baseUrl<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;https://blog.ttbt.work&#34;</span> --buildDrafts
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>hugo --theme<span style="color:#f92672">=</span>hugo-flex --baseUrl<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;https://codebeautiful.gitee.io&#34;</span> --buildDrafts</span></span></code></pre></div>

      
      


  

  

  





  <footer>
    
      
    
      
    
      
        <ul class="Tags">
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/hugo/" rel="tag">hugo</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA%E6%8C%87%E5%8D%97/" rel="tag">博客搭建指南</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/hugo-flex/" rel="tag">hugo-flex</a>
            </li>
          
        </ul>
      
    
  </footer>

    </article>
    
  

  
  <nav>
    
    
      <a class="Pagination Pagination--right u-clickable" href="/page/2/" rel="next">Next »</a>
    
  </nav>




      </div>
    </div>
  </main>
  
  <footer class="Footer">
    <div class="u-wrapper">
      <div class="u-padding">
        开发的乐趣在于相通而不同
      </div>
    </div>
  </footer>


  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?d08a2ad355cb7a065a41be081b43297e";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>

</body>

</html>
